package com.budwk.app.sqfwV2.generator.yuHong;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfwDoc.bo.SqfwExcelForSummaryBO;
import com.budwk.app.sqfwDoc.bo.SqfwExcelJudgeRes;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.SqfwExcelCreateCommonBO;
import com.budwk.app.sqfwV2.component.centuryCity.CommCenturyCityDataHandleUtil;
import com.budwk.app.sqfwV2.dto.dto.yuHong.StaffInfoDTO;
import com.budwk.app.sqfwV2.dto.dto.yuHong.YuHongSafeCheckDTO;
import com.budwk.app.sqfwV2.dto.image.CenturyCityExcelImageConfigBO;
import com.budwk.app.sqfwV2.enums.YuHongEnum;
import com.budwk.app.util.ClassUtil;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 东方祥云低代码1.1
 * @since 2024-04-16
 * <p>
 * 云潭街道安全排查 safe_check_task
 * 欠薪风险排查工作表.xlsx
 */
public class BackPayGenerator extends BaseTemplateExcelGenerator {

    @Override
    protected void customerPopularSheetBaseParam(Map<String, Object> excelParam, SqfwExcelCreateCommonBO excelCreateParam) {
        CommCenturyCityDataHandleUtil.buildUnitName(excelParam, excelCreateParam);
    }

    @Override
    protected boolean addRowDataCondition(SqfwExcelForSummaryBO summaryBO) {
        Sqfw_formSummary_new sqfwFormSummaryNew = summaryBO.getSqfwFormSummaryNew();
        YuHongSafeCheckDTO safeCheckTaskPdfDTO = JSONObject.parseObject(sqfwFormSummaryNew.getParamData(), YuHongSafeCheckDTO.class);
        String type = safeCheckTaskPdfDTO.getType();
        boolean createFlag = false;
        if(type.equals("九小场所")) {
            createFlag = true;
        }
        return createFlag;


    }

    @Override
    protected void customerPopularSheetDataParam(List<Map<String, Object>> listMap, SqfwExcelCreateCommonBO excelCreateParam) {

    }

    @Override
    protected String getTemplateName() {
        return YuHongEnum.BACK_PAY.getTemplatePath();
    }

    @Override
    public String getDownloadFileName() {
        return "欠薪风险排查记录表";
    }

    @Override
    protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParam) {

    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, SqfwExcelForSummaryBO forSummaryBO) {
        Sqfw_formSummary_new sqfwFormSummaryNew = forSummaryBO.getSqfwFormSummaryNew();
        YuHongSafeCheckDTO safeCheckTaskPdfDTO = JSONObject.parseObject(sqfwFormSummaryNew.getParamData(), YuHongSafeCheckDTO.class);
        StaffInfoDTO staffInfoDTO = safeCheckTaskPdfDTO.getStaffInfo();
        Boolean staffInfo = staffInfoDTO.getKey();
        rowDataMap.put("inspectionDate", DateUtil.format(new Date(Long.parseLong(safeCheckTaskPdfDTO.getInspectionDate())), "yyyy-MM-dd HH:mm:ss"));
        if (staffInfo) {
            rowDataMap.put(ClassUtil.getField(YuHongSafeCheckDTO::getStaffInfo), "员工"+ staffInfoDTO.getStaffNumber() +"人");
            rowDataMap.put(ClassUtil.getField(StaffInfoDTO::getPayrollStatus), staffInfoDTO.getPayrollStatus());
        } else {
            rowDataMap.put(ClassUtil.getField(YuHongSafeCheckDTO::getStaffInfo), "家人");
            rowDataMap.put(ClassUtil.getField(StaffInfoDTO::getPayrollStatus), "是");
        }
        rowDataMap.put(ClassUtil.getField(StaffInfoDTO::getPayrollProblem), staffInfoDTO.getPayrollProblem());
        rowDataMap.put(ClassUtil.getField(YuHongSafeCheckDTO::getBusinessType), safeCheckTaskPdfDTO.getBusinessType());
        if(cn.hutool.core.util.StrUtil.isEmpty(safeCheckTaskPdfDTO.getPeers())){
            safeCheckTaskPdfDTO.setPeers( sqfwFormSummaryNew.getCreateUserName());
        }
        rowDataMap.put(ClassUtil.getField(YuHongSafeCheckDTO::getPeers), safeCheckTaskPdfDTO.getPeers());
    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeErgodic(SqfwExcelCreateCommonBO excelCreateParam, Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeCreate(Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected Class<?> getImageConfigBO() {
        return CenturyCityExcelImageConfigBO.class;
    }

    public boolean isGenerateExcel(List<Sqfw_formSummary_new> dataList) {
        return CommCenturyCityDataHandleUtil.checkData(dataList);
    }

}
